import api from "@/util/api";

async function findAll(pageNo = 1, pageSize = 10, params = {}) {
    let resp = await api({
        url: "/rbac-api/perm",
        method: "get",
        params: {
            pageNo,
            pageSize,
            ...params
        }
    });
    return resp.data || resp;
}

async function deleteById(id){
    let resp = await api({
        url:"/rbac-api/perm/deleteById/" + id,
        method:"delete"
    });
    return resp;
}

async function save(perm){
    let resp = await api({
        url:"/rbac-api/perm/add",
        method:"post",
        data: perm,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
    return resp;
}

async function update(perm) {
    let resp = await api({
        url:"/rbac-api/perm/update",
        method:"put",
        data: perm,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
    return resp;
}

async function deleteAll(ids){
    let resp = await api({
        url:"/rbac-api/perm/delete",
        method:"delete",
        params: { ids: ids },
        paramsSerializer: {
            indexes: null
        }
    });
    return resp;
}
async function findPById(id){
    let resp = await api({
        url:"/rbac-api/api/v1/perm/findById/id"+id,
        method:"get",
    })
    return resp;
}
async function findPAll(params) {
    let resp = await api({
        url:"/rbac-api/perm",
        method:"get",
        params
    })
    return resp;
}
export {findAll, deleteById, save, update, deleteAll,findPById,
    findPAll,};